//
//  MZFileManager.swift
//  MZTool
//
//  Created by gby on 2023/1/28.
//

import Foundation

open class MZFileManager {
    public static let shared = MZFileManager()
    
    public func getDocPath() -> String? {
        return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path
    }
    
    public func getCachePath() -> String? {
        return FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first?.path
    }
    
    public func getLibPath() -> String? {
        return FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).last?.path
    }
    
    public func getTempPath() -> String? {
        return NSTemporaryDirectory()
    }
    
    public func getTempPath(path: String) -> String? {
        let s = NSTemporaryDirectory() as NSString
        s.appendingPathComponent(path)
        return s as String
    }
    
    public func deleteFile(path: String) throws {
        if FileManager.default.fileExists(atPath: path) {
            do {
                try FileManager.default.removeItem(atPath: path)
            } catch  {
                throw error
            }
        }
    }
}
